package cn.mooncode.basketballManage.service.impl;

import cn.mooncode.basketballManage.pojo.RespBean;
import cn.mooncode.basketballManage.pojo.RespPageBean;
import cn.mooncode.basketballManage.service.ISpaceService;
import cn.mooncode.basketballManage.mapper.SpaceMapper;
import cn.mooncode.basketballManage.pojo.Space;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author jwz
 * @since 2021-03-28
 */
@Service
public class SpaceServiceImpl extends ServiceImpl<SpaceMapper, Space> implements ISpaceService {

    @Autowired
    private SpaceMapper spaceMapper;

    /**
     * 获取所有场地信息
     * @param currentPage
     * @param size
     * @param space
     * @return
     */
    @Override
    public RespPageBean getAllSpaces(Integer currentPage, Integer size, Space space) {
        Page<Space> page = new Page<>(currentPage, size);
        IPage<Space> spaceIPage = spaceMapper.getAllSpaces(page, currentPage, size);
        return new RespPageBean(spaceIPage.getTotal(), spaceIPage.getRecords());
    }

    /**
     * 获取可使用的场地信息
     * @return
     */
    @Override
    public RespBean getSelectedSpace() {
        List<Space> spaceList = spaceMapper.getSelectedSpace();
        if (spaceList.isEmpty()) {
            return RespBean.error("无可用场地信息！");
        }
        return RespBean.success("获取成功！", spaceList);
    }

    @Override
    public RespBean updateTeamNum(Integer sid, Integer num) {
        if (spaceMapper.updateTeamNum(sid, num)) {
            return RespBean.success("修改成功！");
        } else {
        return RespBean.error("修改失败！");
        }
    }
}
